import moment from 'dayjs';
import { isArray, isObject, isString } from 'lodash';

export function getYearSelectOpts() {
}

/**
 * 格式化日期
 */
export function dateFmt(t: string) {
    return t && moment(t).format('YYYY/MM/DD HH:mm:ss');
}

/**
 * 保留2位小数
 */
export function numKeep2decimal(num: number) {
    return Math.round(+num * 100) / 100;
}

type ClassNamesArg = string | string[] | { [key: string]: any } | undefined | null | boolean;

/**
 * 合并classname
 * @param args 
 * @returns 
 */
export function cx(...args: ClassNamesArg[]): string {
    const length = args.length;
    let classNames: string[] = [];
    for (let i = 0; i < length; i++) {
      const v = args[i];
      if (!v) {
        continue;
      }
      if (isString(v)) {
        classNames.push(v);
      } else if (isArray(v)) {
        classNames = classNames.concat(v);
      } else if (isObject(v)) {
        Object.keys(v).forEach((k) => {
          if ((v as Record<string, any>)[k]) {
            classNames.push(k);
          }
        });
      } else {
        console.warn(true, 'arguments must be one of string/array/object.');
      }
    }
    return [...new Set(classNames)].join(' ');
}